#include "systemrebootdialog.h"
#include "ui_systemrebootdialog.h"

#include "src/common/xwindowmanager.h"
#include "src/utils/log.h"

SystemRebootDialog::SystemRebootDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SystemRebootDialog)
{
    ui->setupUi(this);
    ui->widgetLock->hide();
    setWindowFlags(windowFlags()|Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);

    connect(ui->btnLock, &QPushButton::clicked, this, &SystemRebootDialog::onLockClicked);
    connect(ui->btnSleep, &QPushButton::clicked, this, &SystemRebootDialog::onSleepClicked);
    connect(ui->btnReboot, &QPushButton::clicked, this, &SystemRebootDialog::onRebootClicked);
    connect(ui->btnShutdown, &QPushButton::clicked, this, &SystemRebootDialog::onShutdownClicked);
}

SystemRebootDialog::~SystemRebootDialog()
{
    delete ui;
}

void SystemRebootDialog::onLockClicked()
{

}

void SystemRebootDialog::onSleepClicked()
{
    accept();
    XWindowManager::windowSystemSleep();
}

void SystemRebootDialog::onRebootClicked()
{
    XWindowManager::windowSystemReboot();
}

void SystemRebootDialog::onShutdownClicked()
{
    XWindowManager::windowSystemShutdown();
}

//void SystemRebootDialog::keyPressEvent(QKeyEvent *keyEvent)
//{
//    switch (keyEvent->key())
//    {
//    case Qt::Key_Escape:
//        break;
//    default:
//        QDialog::keyPressEvent(keyEvent);
//    }
//}

void SystemRebootDialog::mousePressEvent(QMouseEvent *event)
{
    QDialog::mousePressEvent(event);
    accept();
}
